
#ifndef dma_H_
#define dma_H_

//-------------------------------------------------------------------------------------//
#define BytesRcvDelayMax 5    // 10ms
#define RcvDataNumMax    200  // bytes
#define SndDataNumMax    200  // bytes
//-------------------------------------------------------------------------------------//

#define ADD_MONITOR  33
#define TOTAL_MOUDLE 3

#define GAIN_MAX_UP   65  //??????
#define GAIN_MAX_DOWN 70  //??????

#define POW_MAX_UP   23
#define POW_MAX_DOWN 27

//--------------------------------------------------------------------------------------//
//=======PROTOCOL BETWEEN FROM MAINBOARD TO SLAVE MODULE=================
#define OFF_HEAD_MODULE_ADDR 0
#define OFF_HEAD_COMMAND_ID  (OFF_HEAD_MODULE_ADDR + 1)
#define OFF_HEAD_MEMMAP_ADDR (OFF_HEAD_COMMAND_ID + 1)
#define PROTOCOL_HEAD        (OFF_HEAD_MEMMAP_ADDR + 2)

//======PROTOCOL BETWEEN FROM SLAVE TO MAINBOARD MODULE==================
#define ANSWER_RESPONSE 0

//====NUMBER OF PROTOCOL====================================================
#define NUM_MODULE_ADDRESS 1
#define NUM_MEMMAP_VERSION 3
#define NUM_COMMAND_ID     1
#define NUM_RESPONSE_ID    1
#define NUM_MEMMAP_ADDRESS 2
#define NUM_DATA_LENGTH    1

//=========================== COMMAND ID ==============================================================
#define C_CMD_RESET          0x00  //????
#define C_CMD_READ_RAM       0x01  //?????RAM???
#define C_CMD_WRITE_RAM      0x03  //???????RAM?
#define C_CMD_READ_SECTOR    0x04  //??flash??
#define C_CMD_WRITE_SECTOR   0x05  //????flash???(64bytes)
#define C_CMD_STORE_DEFAULTS 0x06  //??????????????

#define C_CMD_READ_RAM_N  0x21  //??RAM???????
#define C_CMD_WRITE_RAM_N 0x23  //?????????RAM

#define C_CMD_POWER_CAL 0x25  //????
#define C_CMD_POWUP_CAL 0x26  //????

#define C_CMD_INITIAL_MEMMAP 0xFF

//=========================== Response ID =============================================================
#define C_SUCCESS             0x00  //??
#define C_INVALID_CHARACTER   0x01  //???????
#define C_ODD_CHAR_COUNT      0x02  //?????????
#define C_BUFFER_OVERFLOW     0x03  //???????
#define C_UNKNOWN_COMMAND     0x04  //????
#define C_INVALID_PARAM_COUNT 0x05  //??????
#define C_PARAM_OFF_RANGE     0x06  //???????????
#define C_LEVEL_TOO_LOW       0x10
#define C_LEVEL_TOO_HIGH      0x11
#define C_LIMITS_ERROR        0x12
#define C_RW_AUTHOR_ERROR     0x13

//===========================MODULE ATTRIBUTE========================================================
#define MODULE_ATTRIBUTE      0x40
#define MODULE_Soft_Version   0x00
#define MODULE_Memmap_Numbers 31
#define Data_Address_Start    0x00

//==========RAM ???? for DMA======================================================================/
#define MODULE_FC      0x0000 + 0           // 0		????
#define MODULE_VERSION MODULE_FC + 1        // 1	        ??
#define PUBLISH_DATE   MODULE_VERSION + 20  // 21	        ??

#define ALARM_1       PUBLISH_DATE + 8   // 29	        ??1
#define POWER_DOWN    ALARM_1 + 1        // 30	        ????
#define CONFIG_HIGH   POWER_DOWN + 1     // 31	        ????
#define CONFIG_LOW    CONFIG_HIGH + 1    // 32	        ????
#define ATT_DL        CONFIG_LOW + 1     // 33		????
#define ATT_UL        ATT_DL + 1         // 34		????
#define SMART_MODE    ATT_UL + 1         // 35		????
#define DL_AGC_VOLT   SMART_MODE + 1     // 36		Range???
#define UL_AGC_VOLT   DL_AGC_VOLT + 2    // 38		Range???
#define DL_POWER_VOLT UL_AGC_VOLT + 2    // 40		?????????
#define UL_POWER_VOLT DL_POWER_VOLT + 2  // 42		?????????
#define POWER_CAL_SYB UL_POWER_VOLT + 2  // 44		??????
#define DL_OSC_FREQ   POWER_CAL_SYB + 1  // 45		??????
#define UL_OSC_FREQ   DL_OSC_FREQ + 2    // 47		??????
#define SIGNAL_SET_2  UL_OSC_FREQ + 2    // 49		2???
#define SIGNAL_SET_1  SIGNAL_SET_2 + 2   // 51		1???
#define DL_CAL_VOLT   SIGNAL_SET_1 + 2   // 53		?????
#define MAX_POWER_DN  DL_CAL_VOLT + 40   // 93
#define UL_CAL_VOLT   MAX_POWER_DN + 1   // 94		?????
#define MAX_POWER_UP  UL_CAL_VOLT + 40   // 134
#define ALARM_2       MAX_POWER_UP + 1   // 135	        ??1
#define POWER_UP      ALARM_2 + 1        // 136	        ????
#define POWUP_CAL_SYB POWER_UP + 1       // 137		??????
#define POWER_REF_DN  POWUP_CAL_SYB + 1  // 138	        ??????
#define POWER_REF_UP  POWER_REF_DN + 1   // 139	        ??????

#define NUM_BUF_MAX POWER_REF_UP + 1  // 140

#define ADDR_TOTAL_MOUDLE  0
#define ADDR_NO_MOUDLE     ADDR_TOTAL_MOUDLE + 1
#define ADDR_GAIN_MAX_UP   ADDR_NO_MOUDLE + 1
#define ADDR_GAIN_MAX_DOWN ADDR_GAIN_MAX_UP + 1
#define ADDR_POW_MAX_UP    ADDR_GAIN_MAX_DOWN + 1
#define ADDR_POW_MAX_DOWN  ADDR_POW_MAX_UP + 1

#define BOARD_MAX 6

void Serial_Init(void);
void inquire_event(void);
void SerialRcvEvent(void);
void trans_event(void);

void Pc_Init(void);
void PcRcvEvent(void);
#endif
